package com.ss.android.article.browser.view.user;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ItemDecoration;
import android.support.v7.widget.RecyclerView.LayoutParams;
import android.support.v7.widget.RecyclerView.State;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;

import com.bytedance.common.utility.UIUtils;
import com.ss.android.article.browser.database.BrowserHistory;

import java.util.List;

public final class x extends ItemDecoration {
    public static final class a {
        public boolean a;
        public boolean b;

        public a() {

        }
    }

    List<BrowserHistory> a;
    private final float b;
    private final float c;
    private final Paint d;
    private final Paint e;
    private final float f;
    private final Paint g;

    public x(Context arg7) {

        this.b = UIUtils.dp2px(arg7, 20f);
        this.f = this.b;
        this.c = UIUtils.dp2px(arg7, 0.5f);
        this.d = new Paint();
        this.d.setAntiAlias(true);
        this.d.setColor(arg7.getResources().getColor(com.ss.android.article.browser.R.color.fv));
        this.e = new Paint();
        this.e.setAntiAlias(true);
        this.e.setColor(arg7.getResources().getColor(com.ss.android.article.browser.R.color.g1));
        this.e.setTextSize(TypedValue.applyDimension(2, 10f, arg7.getResources().getDisplayMetrics()));
        this.g = new Paint();
        this.g.setAntiAlias(true);
        this.g.setStrokeWidth(this.c);
        this.g.setColor(arg7.getResources().getColor(com.ss.android.article.browser.R.color.fv));
    }

    public final void getItemOffsets(Rect arg3, View arg4, RecyclerView arg5, State arg6) {
        if (((x.a) arg4.getTag()).a) {
            arg3.set(0, ((int) this.b), 0, 0);
        } else {
            arg3.set(0, ((int) this.c), 0, 0);
        }
    }

    public final void onDraw(Canvas arg13, RecyclerView arg14, State arg15) {
        float v11 = 2f;
        int v7 = arg14.getChildCount();
        int v6;
        for (v6 = 0; v6 < v7; ++v6) {
            View v4 = arg14.getChildAt(v6);
            int v8 = arg14.getChildAdapterPosition(v4);
            if (v8 == -1 || !((x.a) v4.getTag()).a) {
                arg13.drawLine(this.f + (((float) arg14.getPaddingLeft())),
                        (((float) v4.getTop())) - this.g.getStrokeWidth() / v11,
                        ((float) (arg14.getWidth() - arg14.getPaddingRight())),
                        (((float) v4.getTop())) - this.g.getStrokeWidth() / v11, this.g);
            } else {
                ViewGroup.LayoutParams v0 = v4.getLayoutParams();
                int v9 = arg14.getPaddingLeft();
                int v3 = arg14.getWidth() - arg14.getPaddingRight();
                int v0_1 = v4.getTop() - ((LayoutParams) v0).topMargin - Math.round(ViewCompat.getTranslationY(v4));
                int v2 = ((int) ((((float) v0_1)) - this.b));
                Rect v1 = new Rect(v9, v2, v3, v0_1);
                Paint.FontMetricsInt v4_1 = this.e.getFontMetricsInt();
                int v10 = (v1.top + v1.bottom - v4_1.bottom - v4_1.top) / 2;
                arg13.drawRect(((float) v9), ((float) v2), ((float) v3), ((float) v0_1), this.d);
                arg13.drawText(this.a.get(v8).readableTime, (((float) v9)) + this.f, ((float) v10), this.e);
            }
        }
    }

    public final void onDrawOver(Canvas arg10, RecyclerView arg11, State arg12) {
        int v4_1;
        int v0_1;
        View v4 = arg11.getChildAt(0);
        View v1 = arg11.getChildAt(1);
        if (v4 != null && v1 != null) {
            Object v0 = v4.getTag();
            Object v1_1 = v1.getTag();
            int v6 = arg11.getChildAdapterPosition(v4);
            int v7 = arg11.getPaddingLeft();
            int v5 = arg11.getWidth() - arg11.getPaddingRight();
            int v3 = ((int) this.b);
            if (!((a) v0).b || !((a) v1_1).a || (((float) v4.getBottom())) > this.b) {
                v0_1 = 0;
                v4_1 = v3;
            } else {
                int v1_2 = v4.getBottom();
                v0_1 = ((int) ((((float) v1_2)) - this.b));
                v4_1 = v1_2;
            }

            Rect v1_3 = new Rect(v7, v0_1, v5, v4_1);
            Paint.FontMetricsInt v2 = this.e.getFontMetricsInt();
            int v8 = (v1_3.top + v1_3.bottom - v2.bottom - v2.top) / 2;
            arg10.drawRect(((float) v7), ((float) v0_1), ((float) v5), ((float) v4_1), this.d);
            arg10.drawText(this.a.get(v6).readableTime, (((float) v7)) + this.f, ((float) v8), this.e);
        }
    }
}

